#ifndef LAYOUT_H
#define LAYOUT_H

#include <QObject>
#include <QDateTime>
#include <QRegExp>

#define DEFAULT_DATETIME_FORMAT "yyyy-MM-dd HH:mm:ss.zzz"
#define DEFAULT_PATTERN "%d [%16c] - [%p] %m"

namespace Log4Qt
{
    class Layout : public QObject
    {
        Q_OBJECT
    public:
        explicit Layout(const QString &pattern = DEFAULT_PATTERN);

        QString format(const QString &loggerName,
                       const char *fileName,
                       int fileLine,
                       const QString &level,
                       const QString &msg);

    protected:
        QString name;
        QString pattern;

        QString formatter;

        bool dateTimeFlag;    // %d %d{yyyy-MM-dd HH:mm:ss.zzz}
        bool loggerNameFlag;  // %c %12c
        bool fileNameFlag;    // %F %16F
        bool fileLineFlag;    // %l
        bool messageFlag;     // %m
        bool prioriryFlag;    // %p

        QString dateTimeFormat;
        int loggerNameLength;
        int fileNameLength;
        int fileLineLength;
        int prioriryLength;

    private:
        void parse();
    };
}


#endif // LAYOUT_H
